<% add_decidim_page_title(t("decidim.admin.titles.scopes")) %>
<div class="card">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <% if parent_scope %>
        <%= scope_breadcrumbs(parent_scope).join(" - ").html_safe %> <%= link_to t("actions.add", scope: "decidim.admin"), new_scope_scope_path(parent_scope), class: "button button__sm button__secondary" if allowed_to? :create, :scope %><%= link_to t("actions.edit", scope: "decidim.admin"), edit_scope_path(parent_scope), class: "button button__sm button__secondary" if allowed_to? :edit, :scope, scope: parent_scope %>
      <% else %>
        <%= t "decidim.admin.titles.scopes" %> <%= link_to t("actions.add", scope: "decidim.admin"), new_scope_path, class: "button button__sm button__secondary" if allowed_to? :create, :scope %>
      <% end %>
    </h1>
  </div>

  <div class="flash warning"><%= t("scopes.deprecated", scope: "decidim.admin") %></div>

  <% if @scopes.any? %>
    <div class="table-stacked">
      <table class="table-list">
      <thead>
        <tr>
          <th><%= t("models.scope.fields.name", scope: "decidim.admin") %></th>
          <th><%= t("models.scope.fields.scope_type", scope: "decidim.admin") %></th>
          <th><%= t("decidim.admin.actions.actions") %></th>
        </tr>
      </thead>
      <tbody>
        <% @scopes.each do |scope| %>
          <tr>
            <td data-label="<%= t("models.scope.fields.name", scope: "decidim.admin") %>">
              <%= link_to translated_attribute(scope.name), scope_scopes_path(scope) %>
            </td>
            <td data-label="<%= t("models.scope.fields.scope_type", scope: "decidim.admin") %>">
              <%= scope.scope_type ? translated_attribute(scope.scope_type.name) : "-" %>
            </td>
            <td data-label="<%= t("decidim.admin.actions.actions") %>" class="table-list__actions">
              <button type="button" data-controller="dropdown" data-target="actions-scope-<%= scope.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: translated_attribute(scope.name)) %>">
                <%= icon "more-fill", class: "text-secondary" %>
              </button>

              <div class="inline-block relative">
                <ul id="actions-scope-<%= scope.id %>" class="dropdown dropdown__action" aria-hidden="true">
                  <% if allowed_to? :update, :scope, scope: scope %>
                    <li class="dropdown__item">
                      <%= link_to [:edit, scope], method: :get, class: "dropdown__button" do %>
                        <%= icon "pencil-line" %>
                        <%= t("actions.edit", scope: "decidim.admin") %>
                      <% end %>
                    </li>

                    <hr>
                  <% end %>

                  <li class="dropdown__item">
                    <%= link_to scope_scopes_path(scope), method: :get, class: "dropdown__button" do %>
                      <%= icon "zoom-in-line" %>
                      <%= t("actions.browse", scope: "decidim.admin") %>
                    <% end %>
                  </li>

                  <% if allowed_to? :destroy, :scope, scope: scope %>
                    <hr>

                    <li class="dropdown__item">
                      <%= link_to scope, method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button" do %>
                        <%= icon "delete-bin-line" %>
                        <%= t("actions.destroy", scope: "decidim.admin") %>
                      <% end %>
                    </li>
                  <% end %>
                </ul>
              </div>
            </td>
          </tr>
        <% end %>
      </tbody>
      </table>
    </div>
  <% else %>
    <p><%= t("decidim.admin.scopes.no_scopes") %></p>
  <% end %>
</div>
